﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Windows.UI.Xaml;

namespace StyleMVVM.LanguageExtensions
{
	public static class FrameworkElementExtensions
	{
		public static object TryFindResouce(this FrameworkElement element, object resourceKey)
		{
			object returnValue = null;

			FrameworkElement currentElement = element;

			while (currentElement != null)
			{
				if (currentElement.Resources.TryGetValue(resourceKey, out returnValue))
				{
					return returnValue;
				}

				currentElement = currentElement.Parent as FrameworkElement;
			}

			Application.Current.Resources.TryGetValue(resourceKey, out returnValue);

			return returnValue;
		}
	}
}